const sliderWidth = 96
const network = require('../../utils/network.js')
// create("待支付"),
//   pay_finish("已支付"),
//   waiting_deal("待处理"),
//   waiting_deliver("待发货"),
//   finish("已完成");

const orderStatus =[
  null,
  'create',
  'waiting_deliver',
  'finish'
]
Page({
  pageInfo: {
    page: 1,
    pageSize: 20
  },
  data: {
    tabs: ['全部', '待付款', '待发货', '待收货'],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    msg1: {
      title: '空空如也',
      text: '暂时没有相关数据',
    },
    msg2: {
      icon: '../../assets/images/order/iconfont-order.png',
      title: '您还没有相关的订单',
      text: '可以去看看有哪些想买',
      buttons: [{
        text: '随便逛逛',
      }],
    },
    msg3: {
      icon: '../../assets/images/order/iconfont-empty.png',
      title: '暂无待评价订单',
    },
    
    orders:[]
  },
  onLoad() {
    this.getSystemInfo()

    //默认加载全部订单
    this.requestAllOrders();
  },

  requestAllOrders:function(){

    const params = Object.assign({},this.pageInfo,{
      orderStatus: orderStatus[this.data.activeIndex]
    })
    network.requestLoading('mp/client/shopOrder/shopOrderList', params, '', res => {
      this.setData({
        orders: res.data.content
      })
    }, err => {

    })
  },

  getSystemInfo() {
    const that = this
    wx.getSystemInfo({
      success(res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
        })
      }
    })
  },
  tabClick(e) {
    const { offsetLeft, dataset } = e.currentTarget
    const { id } = dataset
    this.setData({
      sliderOffset: offsetLeft,
      activeIndex: id,
    })
    this.requestAllOrders();
  },
  buttonClicked(e) {
    console.log(e)
  },
})
